package intelligentCustomer.planning;

import dev.langchain4j.model.openai.OpenAiStreamingChatModel;

/**
 * 推荐步骤
 * 生成个性化推荐
 */
public class RecommendationStep implements PlanStep {
    private final String name;
    private final OpenAiStreamingChatModel model;
    private int personalizationLevel = 1; // 个性化程度，用于调整
    
    public RecommendationStep(String name, OpenAiStreamingChatModel model) {
        this.name = name;
        this.model = model;
    }
    
    @Override
    public String execute(PlanningContext context) {
        // 获取前面步骤的结果
        String analysis = context.getResult("需求分析");
        String comparison = context.getResult("特性对比");
        
        String prompt = String.format(
            "基于以下信息，生成个性化推荐。个性化程度：%d\n" +
            "需求分析：%s\n" +
            "特性对比：%s\n" +
            "原始查询：%s\n" +
            "请提供最适合用户需求的推荐。",
            personalizationLevel,
            analysis != null ? analysis : "未提供",
            comparison != null ? comparison : "未提供",
            context.getQuery()
        );
        
        return ReasonGenerator.generate(model, prompt);
    }
    
    @Override
    public String getName() {
        return name;
    }
    
    @Override
    public void adjustParameters(PlanningContext context) {
        // 根据重试次数增加个性化程度
        personalizationLevel = Math.min(3, personalizationLevel + 1);
    }
} 